package com.gtw.modules.api.controller;

import com.gtw.common.annotation.LoginUserApi;
import com.gtw.common.utils.Query;
import com.gtw.common.utils.R;
import com.gtw.dto.TbUserFriendDto;
import com.gtw.modules.api.service.TbUserService;
import com.gtw.modules.entity.TbUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/** 朋友圈
 * Created by wuye on 2018/3/14.
 */
@RestController
@RequestMapping("/api/friend")
public class TbFriendController {

    @Autowired
    private TbUserService tbUserService;


    /**
     *  查询我的朋友圈 四个等级 分别的数量
     * @return
     */
    @RequestMapping("/foundByTypeCount")
    public R foundByTypeCount(@LoginUserApi TbUser tbUser,@RequestParam Integer type,@RequestParam Map<String, Object> params){
        int IronsNum = tbUserService.foundByOne(tbUser.getUserId());
        int FriendNum = tbUserService.foundByTwo(tbUser.getUserId());
        int acpNum = tbUserService.foundByThree(tbUser.getUserId());
        int fansNum = tbUserService.foundByFour(tbUser.getUserId());
        List<TbUser> list = new ArrayList<>();
        params.put("id",tbUser.getUserId());
        //查询列表数据
        Query query = new Query(params);
        if(type == 1) {
            //查询铁杆
            list = tbUserService.queryByOnd(query);
        }
        if(type == 2) {
            //查询朋友
            list = tbUserService.queryByTwo(query);
        }
        if(type == 3) {
            //查询熟人
            list = tbUserService.queryByThree(query);
        }
        if(type == 4) {
            //粉丝
            list = tbUserService.queryByFour(query);
        }
        List<TbUser> list2 = new ArrayList<>();
        for (int i = 0;i<list.size();i++){
            TbUser user = list.get(i);
            user.setMobile("");
            user.setPassword("");
            user.setPaypwd("");
            list2.add(user);
        }
        TbUserFriendDto dto = new TbUserFriendDto();
        dto.setIronsNum(IronsNum);
        dto.setAcpNum(acpNum);
        dto.setFriendNum(FriendNum);
        dto.setFansNum(fansNum);
        dto.setUserList(list2);
        return R.ok().put("data",dto);
    }
}
